﻿using System;
using System.Collections.Generic;
using System.Text;

using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.Common;
using System.Data;
using TRPOP.Common;

namespace TRPOP.ComSqlDAL
{
    /// <summary>
    /// 
    /// </summary>
    public interface ICommonDAL
    {
        /// <summary>
        /// 拼装单表搜索信息的SQL查询语句
        /// </summary>
        /// <param name="intTopn"></param>
        /// <param name="strCondition"></param>
        /// <param name="strOrderby"></param>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        string strbuildSqlForList(int intTopn, string strCondition, string strOrderby, string strTableName);

        /// <summary>
        /// 执行SQL语句 获取dataset
        /// 需要制定sql连接字符串
        /// </summary>
        /// <param name="strSqlString"></param>
        /// <param name="strConn"></param>
        /// <returns></returns>
        DataSet GetDataSet(string strSqlString, string strConn);

        /// <summary>
        /// 执行SQL语句 获取dataset
        /// 需要制定sql连接字符串
        /// </summary>
        /// <param name="strSqlString"></param>
        /// <param name="strConn"></param>
        /// <returns></returns>
        DataSet GetDataSetByReader(string strSqlString, string strConn);

        /// <summary>
        /// 通过 SqlDatabase  DbCommand 获取数据集
        /// </summary>
        /// <param name="oSqlDatabase"></param>
        /// <param name="oDbCommand"></param>
        /// <returns></returns>
        DataSet GetDataSet(SqlDatabase oSqlDatabase, DbCommand oDbCommand);

        /// <summary>
        /// 通过 SqlDatabase  DbCommand 获取数据集
        /// 并且返回记录数
        /// </summary>
        /// <param name="oSqlDatabase"></param>
        /// <param name="oDbCommand"></param>
        /// <param name="recordCount"></param>
        /// <returns></returns>
        DataSet GetDataSet(SqlDatabase oSqlDatabase, DbCommand oDbCommand, out int recordCount);

        /// <summary>
        /// 获取分页列表
        /// </summary>
        /// <param name="strTableName"></param>
        /// <param name="strShowColumns"></param>
        /// <param name="pageNumber"></param>
        /// <param name="pageSize"></param>
        /// <param name="condition"></param>
        /// <param name="orderby"></param>
        /// <param name="recordCount"></param>
        /// <param name="strSqlConn"></param>
        /// <returns></returns>
        DataSet GetListByPager(string strTableName, string strShowColumns, int pageNumber, int pageSize, string condition, string orderby, out int recordCount, string strSqlConn);


        /// <summary>
        /// 泛型 获取列表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="strSelectQuery"></param>
        /// <param name="strSqlConn"></param>
        /// <returns></returns>
        List<T> GetListByCondition<T>(string strSelectQuery, string strSqlConn);

        /// <summary>
        /// 通过DataReader的方式读取数据
        /// </summary>
        /// <param name="strSelectQuery"></param>
        /// <param name="strSqlConn"></param>
        /// <returns></returns>
        DataTable GetDatatablebyReader(string strSelectQuery, string strSqlConn);

        /// <summary>
        /// 执行SQL语句
        /// </summary>
        /// <param name="strSqlString"></param>
        /// <param name="strSqlConn"></param>
        /// <returns></returns>
        EnumSubmitResult ExeSQLQuery(string strSqlString, string strSqlConn);

        /// <summary>
        /// 根据  SqlDatabase  DbCommand 执行
        /// </summary>
        /// <param name="oSqlDatabase"></param>
        /// <param name="oDbCommand"></param>
        /// <returns></returns>
        EnumSubmitResult ExeByCommandSqlDatabase(SqlDatabase oSqlDatabase, DbCommand oDbCommand);

        /// <summary>
        /// 返回 SqlDatabase
        /// </summary>
        /// <param name="strSqlConn"></param>
        /// <returns></returns>
        SqlDatabase GetSqlDatabase(string strSqlConn);
    }

    /// <summary>
    /// 
    /// </summary>
    public class ICommonDALAccess
    {
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static ICommonDAL GetSQLSvererInstance()
        {
            return (ICommonDAL)new CommonDAL();
        }
    }
}
